package com.hqy.product.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hqy.product.dto.SkuInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

/**
 * skuinfo表的mapper映射
 */
@Mapper
public interface SkuInfoMapper extends BaseMapper<SkuInfo> {

    /**
     * 扣减库存
     * @param skuId
     * @param num
     * @return
     */
    @Update("update sku_info set stock = stock - #{num} where id = #{skuId} and stock >= #{num};")
    public int decountStock(Long skuId, Integer num);

    /**
     * 回滚库存
     * @param skuId
     * @param num
     * @return
     */
    @Update("update sku_info set stock = stock + #{num} where id = #{skuId};")
    public int rollbackStock(Long skuId, Integer num);
}
